<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>blue's Thymeleaf</title>
    <link rel="stylesheet" href="css/login.css">
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container">
    <form name="f" action="login" method="post">
        <div class="login-form">
            <div class="text">用户登录</div>
            <div style="height: 15px;"></div>
            <div class="form-item">
                <input type="text" name="username" placeholder="用户名"><br>
                <div style="height: 10px;"></div>
                <input type="password" name="password" placeholder="密码">
                <!--获取第三方app传递过来的客户端授权参数信息-->
                <input type="hidden" id="clientId" name="clientId" placeholder="客户端id">
                <input type="hidden" id="redirectUri" name="redirectUri" placeholder="登录后成功跳转uri">
                <input type="hidden" id="responseType" name="responseType" placeholder="授权类型">
                <input type="hidden" id="state" name="state" placeholder="state">
            </div>
            <div style="height: 15px;"></div>
            <button class="btn" type="submit">授权并登录</button>
            <div class="btn-back"></div>
            <div class="other">
                没有账号？<a href="#">去注册</a>
            </div>
            <p style="color: red" th:if="${session.SPRING_SECURITY_LAST_EXCEPTION}"
               th:text="${session.SPRING_SECURITY_LAST_EXCEPTION.message}"/>
        </div>
    </form>
</div>
</body>
<script>
    let clientId = getQueryVariable("client_id");
    let redirectUri = getQueryVariable("redirect_uri");
    let responseType = getQueryVariable("response_type");
    let state = getQueryVariable("state");
    if (clientId != null) {
        $("#clientId").val(clientId);
    }
    if (redirectUri != null) {
        $("#redirectUri").val(redirectUri);
    }
    if (responseType != null) {
        $("#responseType").val(responseType);
    }
    if (state != null) {
        $("#state").val(state);
    }

    /**
     * 获取url参数
     */
    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i = 0; i < vars.length; i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
                return pair[1];
            }
        }
        return '';
    }
</script>
</html>